
import React from 'react';
import useTable from "@/cms/use/useTable";
import {Button, message, Modal, Space} from "antd";
import useAddEdit from "./useAddEdit";

function Mtq(props) {

    const {queryList,tableDOM} = useTable({
        columns:[
            {
                title:"套餐名称",
                dataIndex:"packageName",
            },
            {
                title:"美团点评编号",
                dataIndex:"mtId",
            },
            {
                title:"时长",
                dataIndex:"duration",
            },
            {
                title:"操作",
                render(_,record){
                    return <Space>
                        <a onClick={()=>setOpen?setOpen(record):""}>编辑</a>
                        <a style={{color:"red"}} onClick={()=>remove(record)}>删除</a>
                    </Space>
                }
            }
        ],
        xhr:{
            query:"/app/mtqList",
        },
    })

    const {ModalDOM,setOpen} = useAddEdit({
        queryList
    })
    function remove(record){
        Modal.confirm({
            title:"确认要删除吗？",
            onOk(){
                return new Promise((resolve, reject) => {
                    ax.post("/app/deleteTgq",{
                        id:record.ID
                    }).then(res=>{
                        message.success(res.msg);
                        queryList({
                            current:1
                        });
                        resolve()
                    }).catch(err=>{
                        reject(err)
                    })
                })
            }
        })

    }
    return (
        <div>
            {ModalDOM}
            <Button type={"primary"} onClick={()=>setOpen(true)}>添加</Button>
            {tableDOM}
        </div>
    );
}

export default Mtq;